//
//  HMCalendarCell.m
//  MotherBaby
//
//  Created by mengxiangyu on 2017/7/9.
//  Copyright © 2017年 mengxiangyu. All rights reserved.
//

#import "HMCalendarCell.h"

@interface HMCalendarCell ()
@property (strong, nonatomic) UILabel *dayLabel;
@property (strong, nonatomic) UIImageView *leftBottomImage;
@property (strong, nonatomic) UIImageView *rightTopImage;
@property (strong, nonatomic) UIImageView *rightBottomImage;
@property (strong, nonatomic) UILabel *todayLabel;
@end

@implementation HMCalendarCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.cornerRadius = 2;
        self.layer.masksToBounds = YES;
        self.backgroundColor = [UIColor whiteColor];
        
        _dayLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width*0.45, frame.size.height*0.45)];
        _dayLabel.textColor = [UIColor darkGrayColor];
        _dayLabel.font = [UIFont systemFontOfSize:13];
        _dayLabel.textAlignment = NSTextAlignmentCenter;
        _dayLabel.adjustsFontSizeToFitWidth = YES;
        [self addSubview:_dayLabel];
        
    }
    return self;
}

- (void)setModel:(HMCalendarModel *)model {
    _model = model;
    
    if (model.monthType==1) {
        self.backgroundColor = [UIColor whiteColor];
        _dayLabel.alpha = 1;
    } else {
        self.backgroundColor = rgba(245, 245, 245, 1);
        _dayLabel.alpha = 0.6;
    }
    
    _dayLabel.text = [[NSNumber numberWithInteger:model.day] stringValue];
    if (model.isToday) {
        [self addSubview:self.todayLabel];
    } else {
        [_todayLabel removeFromSuperview];
    }
}

// 左下
- (UIImageView *)leftBottomImage {
    if (!_leftBottomImage) {
        _leftBottomImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.frame.size.height*0.6, self.frame.size.width*0.4, self.frame.size.height*0.4)];
    }
    return _leftBottomImage;
}

// 右上
- (UIImageView *)rightTopImage {
    if (!_rightTopImage) {
        _rightTopImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width*0.6, 0, self.frame.size.width*0.4, self.frame.size.height*0.4)];
    }
    return _rightTopImage;
}

// 右下
- (UIImageView *)rightBottomImage {
    if (!_rightBottomImage) {
        _rightBottomImage = [[UIImageView alloc] initWithFrame:CGRectMake(self.frame.size.width*0.6, self.frame.size.height*0.6, self.frame.size.width*0.4, self.frame.size.height*0.4)];
    }
    return _rightBottomImage;
}

- (UILabel *)todayLabel {
    if (!_todayLabel) {
        _todayLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.frame.size.width*0.5, self.frame.size.height*0.5, self.frame.size.width*0.5, self.frame.size.height*0.5)];
        _todayLabel.text = @"今天";
        _todayLabel.adjustsFontSizeToFitWidth = YES;
        _todayLabel.textColor = Color_Subject;
        _todayLabel.font = [UIFont systemFontOfSize:10];
        _todayLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _todayLabel;
}
@end
